<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<link rel="stylesheet" href="<%=path%>/css/pintuer.css">
<link rel="stylesheet" href="<%=path%>/css/admin.css">
<link rel="shortcut icon" href="<%=path%>/images/login.jfif">
<script src="<%=path%>/js/jquery.js"></script>
<script type="text/javascript">
	
</script>

</head>

<body>
	<div class="panel admin-panel">
		<div class="panel-head" id="add">
			<strong><span class="icon-pencil-square-o"></span>增加医疗机构</strong>
		</div>
		<div class="body-content">
			<form id="form-addrole" method="post" class="form-x">
				<input id="fid" name="fid" value="" type="hidden" />
				<div class="form-group">
					<div class="label">
						<label>医疗机构编号：</label>
					</div>
					<div class="field field-icon-right">
						<input type="text" class="input w50 input input-big" value=""
							name="mechanism_id" id="mechanism_id_input" placeholder=""
							data-validate="required:" /> <span></span>
						<div class="tips"></div>
					</div>
				</div>
				<div class="form-group">
					<div class="label">
						<label>医疗机构名称：</label>
					</div>
					<div class="field">
						<input type="text" class="input w50" value="" name="mechanism_name"
							id="mechanism_name_input" data-validate=" required:" /><span></span>
						<div class="tips"></div>
					</div>
				</div>
				<div class="form-group">
					<div class="label">
						<label>医疗机构级别：</label>
					</div>
					<div class="field">
						<input type="text" class="input w50" value="" name="mechanism_rank"
							id="mechanism_rank_input" data-validate=" required:" />
						<div class="tips"></div>
					</div>
				</div>
				<div class="form-group">
					<div class="label">
						<label>所属行政区域：</label>
					</div>
					<div class="field">
						<select id="area_id" class="input w50" name="area_id">
							<option value="0">选择行政区域</option>
						</select>
						<div class="tips"></div>
					</div>
				</div>
				
				<div class="form-group">
					<div class="label">
						<label></label>
					</div>
					<div class="field">
						<button id="add_btn" class="button bg-main icon-check-square-o"
							onclick="addMechanism()" type="button">提交</button>
					</div>
				</div>
			</form>
		</div>
	</div>

</body>
<script type="text/javascript">
	//异步加载行政区域信息
	$(document).ready(function() {
		$.ajax({
			type : "post",
			datatype : "json",
			url : "<%=path%>/area/area_loadArea",
			async : false,
			success : function(result) {
				$.each(result.extend.arealist, function() {
					var optionEle = $("<option></option>").append(this.area_name).attr("value", this.area_id);
					optionEle.appendTo("#area_id");
				})

			}
		})
	});
	//添加医疗机构
	function addMechanism() {
		var mechanism_id = $("#mechanism_id_input").val();
		var mechanism_name = $("#mechanism_name_input").val();
		var mechanism_rank = $("#mechanism_rank_input").val();
		var area_id = $("#area_id").val();
		$.ajax({
			type : "post",
			url : "<%=path%>/mechanism/mechanism_add_action",
			data : {
				mechanism_id: mechanism_id,
				mechanism_name: mechanism_name,
				mechanism_rank: mechanism_rank,
				area_id: area_id,
			},
			
			success : function(result) {
			  if(result.code==100){
			     alert("添加成功！")
			  }else{
			  	  alert("添加失败！")
			  
			  }

			}
		})
	}
	//校验医疗机构名称是否重复
	$("#mechanism_name_input").change(function() {
		var mechanism_name = this.value;
		$.ajax({
			url : "<%=path%>/mechanism/mechanism_check",
			data : {mechanism_name:mechanism_name},
			type : "post",
			success : function(result) {
			console.log(result)
				if (result.code == 100) {
					show_validate_msg("#mechanism_name_input", "success", "医疗机构名称可用");
				} else {
					show_validate_msg("#mechanism_name_input", "error", "医疗机构名称不可用");
				}
			}
		})
	});
	//校验结果提示信息
	function show_validate_msg(ele, status, msg) {
		//清除当前元素的校验状态
		$(ele).next("span").text("");
		if ("success" == status) {
			$(ele).next("span").text(msg);
		} else if ("error" == status) {
			$(ele).next("span").text(msg);
		}
	}
</script>
</html>
